$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加会员表', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field: 'number',
                title: '编码',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'account',
                title: '登录账号',
                unresize: true,
                align: 'center',
                width:'150'
            }, {
                field: 'nick_name',
                title: '用户名',
                unresize: true,
                align: 'center',
                width:'150'
            }, {
                title: '头像',
                unresize: true,
                align: 'center',
                width:'100',
                templet:function(d){
                    return '<img src="'+d.photo_path+'" onerror="this.src=\'/image/user.png\'" width=80>'
                }
            }, {
                field: 'sex',
                title: '性别',
                unresize: true,
                align: 'center',
                templet:function(d){
                    if(d.sex == 1){
                        return '<span style="color:#34A853">男</span>';
                    }else{
                        return '<span style="color:#EA4335">女</span>';
                    }
                },
                width:'80'
            }, {
                field: 'kaopu',
                title: '靠谱指数',
                unresize: true,
                align: 'center',
                width:'80'
            }, {
                field: 'care_num',
                title: '关注量',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'fans_num',
                title: '粉丝量',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'service_count',
                title: '累计服务',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'zhiye',
                title: '职业',
                unresize: true,
                align: 'center',
                width:'120'
            }, {
                title: '角色',
                unresize: true,
                align: 'center',
                templet:function(d){
                    if(d.grade == 1){
                        return '<span style="color:#34A853">会员</span>';
                    }else{
                        return '<span style="color:#EA4335">普通用户</span>';
                    }
                },
                width:'100'
            }, {
                title: '状态',
                unresize: true,
                align: 'center',
                templet:function(d){
                    if(d.disabled == 1){
                        return '<span style="color:#34A853">正常</span>';
                    }else{
                        return '<span style="color:#EA4335">禁用</span>';
                    }
                },
                width:'80'
            }, {
                field: 'balance',
                title: '账户余额',
                unresize: true,
                align: 'center',
                width:'100'

            }, {
                field: 'from_city',
                title: '所属城市',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'last_login_time',
                title: '最后登录时间',
                unresize: true,
                align: 'center',
                width:'160'
            }, {
                title: '注册方式',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.register_type){
                        case 1 : return '<span style="color:#4285F4">手机号</span>';break;
                        case 2 : return '<span style="color:#EA4335">微信</span>';break;
                        case 3 : return '<span style="color:#FBBC05">QQ</span>';break;
                    }
                },
                width:'100'
            }, {
                field: 'register_time',
                title: '注册时间',
                unresize: true,
                align: 'center',
                width:'150'
            }, {
                title: '操作',
                unresize: true,
                align: 'center',
                toolbar: '#toolbar_normal',
                width:'400'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('编辑会员表', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该会员表吗?', 'bz_user', obj.data.id);
        } else if (obj.event === 'disabled') {
            _ajax_update('确定禁用该会员吗?', 'bz_user', obj.data.id, {
                disabled: 0
            });
        } else if (obj.event === 'enabled') {
            _ajax_update('确定启用该会员吗?', 'bz_user', obj.data.id, {
                disabled: 1
            });
        } else if(obj.event === 'need') {
            layer_iframe('需求列表', '/before/need/index?number=' + obj.data.number);
        }else if(obj.event === 'need_apply') {
            layer_iframe('需求报名列表', '/before/need_apply/index?apply_user=' + obj.data.id);
        }else if(obj.event === 'upgrade') {
            layer_iframe('会员购买记录', '/before/upgrade/index?user_id=' + obj.data.id);
        }else if(obj.event === 'service') {
            layer_iframe('服务列表', '/before/service/index?number=' + obj.data.number);
        }else if(obj.event === 'service_buy') {
            layer_iframe('服务列表', '/before/service_buy/index?buy_user=' + obj.data.id);
        }else if(obj.event === 'red') {
            layer_iframe('红包发布列表', '/before/red_packet/index?user_id=' + obj.data.id);
        }else if(obj.event === 'red_get') {
            layer_iframe('红包领取记录', '/before/red_packet_get/index?get_user_id=' + obj.data.id);
        }else if(obj.event === 'nearby') {
            layer_iframe('动态列表', '/before/nearby/index?user_id=' + obj.data.id);
        }else if(obj.event === 'ad') {
            layer_iframe('广告购买列表', '/before/ad_buy/index?user_id=' + obj.data.id);
        }else if(obj.event === 'coupon') {
            layer_iframe('优惠券发布列表', '/before/coupon/index?user_id=' + obj.data.id);
        }else if(obj.event === 'coupon_get') {
            layer_iframe('优惠券领取列表', '/before/coupon_get/index?get_user_id=' + obj.data.id);
        }

    });
});
